package com.digitalchina.lxnsy.activity.old;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import androidx.viewpager.widget.ViewPager;

import com.digitalchina.lxnsy.R;
import com.digitalchina.lxnsy.adapter.TabViewPagerAdapter;
import com.digitalchina.lxnsy.api.BusinessAgr;
import com.digitalchina.lxnsy.base.BaseActivity;
import com.digitalchina.lxnsy.constant.MSG;
import com.digitalchina.lxnsy.entity.AgrTypeVO;
import com.digitalchina.lxnsy.entity.PagerItemVO;
import com.digitalchina.lxnsy.fragment.NewAgrFragment;
import com.digitalchina.lxnsy.toolkit.FastJsonUtil;
import com.digitalchina.lxnsy.toolkit.GotoUtil;
import com.digitalchina.lxnsy.view.MyTabLayout;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * ================================================
 * 项目名称：BigData
 * 类描述：
 * 包名：com.digitalchina.bigdata.activity
 * 创建人：郑皓
 * 创建时间：2019/4/16 15:26
 * 修改备注：
 * ================================================
 */
public class NewAgricultureActivity extends BaseActivity {
    @Bind(R.id.tab)
    MyTabLayout tab;
    @Bind(R.id.viewpager)
    ViewPager viewpager;

//    private String farmOperationId = ""; // 农事操作id
    private String productStandardId = ""; // 生产标准id
//    private String ID;

    /*每个 tab 的 item*/
    private List<PagerItemVO> mList = new ArrayList<>();

    @Override
    public void setLayout() {
        setContentLayout(R.layout.activity_new_agriculture);
        setTitle("新农艺");
        setRightText("搜索");
    }

    @Override
    public void initMember() {

        productStandardId = (String) getIntent().getSerializableExtra("ID");
//        ID = (String) getIntent().getSerializableExtra("ID");
//        String array[] = ID.split("&");
//
//        farmOperationId = array[0];
//        productStandardId = array[1];

        BusinessAgr.getNewAgrType(this, mHandler);


    }

    @Override
    public void addListener() {

    }

    @Override
    public void setHandler() {
        mHandler = new Handler(new Handler.Callback() {
            @Override
            public boolean handleMessage(Message msg) {
                switch (msg.what) {
                    case MSG.MSG_GET_NEW_AGR_TYPE_SUCCESS:
                        List<AgrTypeVO> list1 = FastJsonUtil.getListBean(msg.obj.toString(), "XNZList", AgrTypeVO.class);
                        List<AgrTypeVO> list2 = FastJsonUtil.getListBean(msg.obj.toString(), "XJSList", AgrTypeVO.class);
                        List<AgrTypeVO> list3 = FastJsonUtil.getListBean(msg.obj.toString(), "XNJList", AgrTypeVO.class);

                        NewAgrFragment new1 = new NewAgrFragment();
                        Bundle b1 = new Bundle();
                        b1.putString("firstTypeCode", "xnz");
//                        b1.putString("farmOperationId", farmOperationId);
                        b1.putString("productStandardId", productStandardId);
                        b1.putSerializable("list", (Serializable) list1);
                        new1.setArguments(b1);

                        NewAgrFragment new2 = new NewAgrFragment();
                        Bundle b2 = new Bundle();
                        b2.putString("firstTypeCode", "xjs");
//                        b2.putString("farmOperationId", farmOperationId);
                        b2.putString("productStandardId", productStandardId);
                        b2.putSerializable("list", (Serializable) list2);
                        new2.setArguments(b2);

                        NewAgrFragment new3 = new NewAgrFragment();
                        Bundle b3 = new Bundle();
                        b3.putString("firstTypeCode", "xnj");
//                        b3.putString("farmOperationId", farmOperationId);
                        b3.putString("productStandardId", productStandardId);
                        b3.putSerializable("list", (Serializable) list3);
                        new3.setArguments(b3);

                        mList.add(new PagerItemVO("新农资", new1));
                        mList.add(new PagerItemVO("新技术", new2));
                        mList.add(new PagerItemVO("新农经", new3));

                        viewpager.setAdapter(new TabViewPagerAdapter(getFragmentManager(), mList));
                        viewpager.setOffscreenPageLimit(3);
                        tab.setViewPager(viewpager);

                        break;
                    case MSG.MSG_GET_NEW_AGR_TYPE_FIELD:
                        showToast(msg.obj.toString());
                        break;
                }
                return false;
            }
        });
    }

    @Override
    public void callBack(Object object) {

    }

    @Override
    public void rightOnClick() {
        GotoUtil.gotoActivity(this,SearchNewAgrActivity.class,"ID",productStandardId);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
